/**
 * 
 */
package org.mhz.ootw.controller;

import javax.annotation.Resource;

import org.mhz.ootw.service.SearchService;
import org.mhz.ootw.util.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Mahan
 *
 * Search controller
 */
@Controller
public class SearchController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(SearchController.class);

    @Resource(name = Constants.TEXT_SEARCH_SERVICE)
    private SearchService mTextSearchService;
    
    /**
     * Handles request for searching by text
     * 
     * @param aSearchText - The text to search
     * @param aSearchItems - The items to search
     * @return The search results
     */
    @RequestMapping(value = Constants.SEARCH_BY_TEXT, method = RequestMethod.GET)
    public @ResponseBody String searchByText(
            @RequestParam(value = Constants.SEARCH_TEXT, required = true) final String aSearchText,
            @RequestParam(value = Constants.SEARCH_ITEMS, required = true) final String aSearchItems)
    {
        final String searchResults = mTextSearchService.getSearchResults(aSearchText, aSearchItems);
        
        LOGGER.trace("Search results >{}<", searchResults);
        
        return searchResults;
    }
}
